import drawQrcode from '../../../utils/qrcode'
import { MineModel } from '../../../models/mine.js'
const ModelMine = new MineModel()
const App = getApp()
Page({
  data: {
    statusBarHeight: App.globalData.statusBarHeight,
    isTabbar: false,
    info: {
      door: {
        title: '线下仓入场券',
        tips: '凭入场券二维码入场'
      },
      user: {
        title: '小蚁买手会员码',
        tips: '会员码用于会员支付,请勿随意泄漏他人'
      }
    }
  },
  onLoad: function(options) {
    console.log('qrcode onLoad=', options)
    const phone = options.phone
    if (options.type == 'door') {
      // 门禁二维码
      this.setData({
        data: this.data.info.door
      })
      ModelMine.getDoorKey().then(res => {
        this.drawQrcode(res.data.doorKey)
      })
    } else {
      // 用户二维码
      this.setData({
        data: this.data.info.user
      })
      this.drawQrcode(phone)
    }
  },
  // 画图
  drawQrcode(params) {
    drawQrcode({
      width: 190,
      height: 190,
      canvasId: 'myQrcode',
      text: params
    })
  }
})
